package com.example.demosession;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author yawn
 * @date 2018-04-22 16:47
 */
@RestController
public class TestController {

    @GetMapping("/s/{name}")
    public String session(@PathVariable String name, HttpSession session) {
        Object user = session.getAttribute("user");
        if (user == null) {
            session.setAttribute("user", name);
        }
        return "已经登陆的用户：" + user + ", session 的id: " + session.getId();
    }
}
